﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LWrap.IndexSource;
namespace LWrap.Index
{
    public class IndexJob
    {
        /// <summary>
        /// Folder path to persist the index files
        /// </summary>
        public string IndexFilePath { get; set; }

        /// <summary>
        /// True: To create new index folder, recreate the folder if exist. False: To append data.
        /// </summary>
        public bool CreateNewIndex { get; set; }

        /// <summary>
        /// Assign the IndexSource object. DBDataSource: Database field indexing 
        /// </summary>
        public IndexDataSource IndexSource { get; set; }

        public IndexJob()
        {
            this.CreateNewIndex = true;
        }

        /// <summary>
        /// The method will initiate the indexing process. IndexFilePath and IndexSource should not be null.
        /// </summary>
        public void ExecuteIndex()
        {
            if (IndexSource == null)
            {
                throw new NullReferenceException("Can't index data. IndexSource should not be null");
            }

            IndexData indxData = new IndexData();
            IndexWriter indexWriter = new IndexWriter(IndexFilePath,CreateNewIndex);

            indxData.CreateIndex(IndexSource,indexWriter);
            
        }
    }
}
